package com.pda.gongpin.view.pagerview;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;


import com.pda.gongpin.R;

import java.util.List;

public class MenuRvAdapter extends RecyclerView.Adapter<MenuRvAdapter.ViewHolder> {
    List<String> list;
    Context context;
    public MenuRvAdapter(List<String> list, Context context) {
        this.list = list;
        this.context=context;
    }

    interface   onItemClickListener
    {
        void  onClick(String businessEntity);
    }

    private onItemClickListener itemClickListener;

    public  void  setOnItemListener(onItemClickListener itemClickListener)
    {
        this.itemClickListener=itemClickListener;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_menu_recyclerview_item, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, @SuppressLint("RecyclerView") final int position) {
        holder.tvName.setText(list.get(position));
      /*  holder.iv_img.setImageResource(list.get(position).getImgSrc());*/
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(itemClickListener!=null)
                    itemClickListener.onClick(list.get(position));
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    static class ViewHolder extends RecyclerView.ViewHolder {

        TextView tvName;
        ImageView iv_img;

        public ViewHolder(View view) {
            super(view);
            tvName = view.findViewById(R.id.tv_name);
            iv_img=view.findViewById(R.id.iv_img);
        }

    }


}
